1 package tw.com.javaworld.CH16;
2 
3 import java.io.*;
4 import javax.servlet.jsp.*;
5 import javax.servlet.jsp.tagext.*;
6 
7 public class AddSimpleTag extends SimpleTagSupport {
8     
9     private int num1 = 0; 
10    private int num2 = 0;
11    
12    public void setNum1(int num1) {
13        this.num1 = num1;
14    }
15    
16    public void setNum2(int num2) {
17        this.num2 = num2;
18    }
19    
20    public void doTag() throws JspException, IOException {
21
22        JspContext ctx = getJspContext();
23        JspWriter out = ctx.getOut();
24            
25        int sum = num1 + num2;
26        ctx.setAttribute("sum", Integer.toString(sum));
27        
28        out.println(num1 + " + " + num2 + " = " + sum);
29    }
30}